package com.cc.bill.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cc.bill.entity.SubmitBillEntity;
import com.cc.common.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cc.bill.entity.SubmitBillNameEntity;
import com.cc.bill.service.SubmitBillNameService;
import com.cc.common.utils.R;


@RestController
@RequestMapping("bill/submitbillname")
@Api(tags="报销项")
public class SubmitBillNameController {
    @Autowired
    private SubmitBillNameService submitBillNameService;

    @PostMapping("/getAllSubmitBill")
    @ApiOperation("获取所有报销项")
    public ResponseData<List<SubmitBillNameEntity>> getAllSubmitBill(){
        List<SubmitBillNameEntity> allSubmitBillNameList = submitBillNameService.list();
        return ResponseData.success(allSubmitBillNameList);
    }

    @GetMapping("/getSubmitBillById")
    @ApiOperation("根据报销项目id获取报销项")
    @ApiImplicitParam(name = "id", value = "报销项目id", paramType = "query", dataType = "Long", required = true)
    public ResponseData<SubmitBillNameEntity> getSubmitBillById(@RequestParam("id")Long id){
        SubmitBillNameEntity submitBillName = submitBillNameService.getOne(new QueryWrapper<SubmitBillNameEntity>().eq("id",id));
        if(submitBillName == null) return ResponseData.success("未查找到该项目名称",true);
        return ResponseData.success(submitBillName);
    }

    @PostMapping("/deleteSubmitBillById")
    @ApiOperation("后台根据报销项目id删除报销项")
    @ApiImplicitParam(name = "id", value = "报销项目id", paramType = "query", dataType = "Long", required = true)
    public ResponseData deleteSubmitBillById(@RequestParam("id")Long id){
        boolean flag = submitBillNameService.removeById(id);
        if (!flag)   return ResponseData.success("删除失败！",true);
        return ResponseData.success("删除成功！",true);
    }

    @PostMapping("/addSubmitBill")
    @ApiOperation("后台添加报销项目")
    @ApiImplicitParam(name = "billName", value = "报销项目名称", paramType = "query", dataType = "String", required = true)
    public ResponseData<List<SubmitBillNameEntity>> addSubmitBill(@RequestParam("billName")String billName){
        SubmitBillNameEntity submitBillNameEntity = new SubmitBillNameEntity();
        submitBillNameEntity.setBillName(billName);
        boolean flag = submitBillNameService.save(submitBillNameEntity);
        if (!flag)   return ResponseData.success("添加失败！",true);
        return ResponseData.success("添加成功！",true);
    }
//
//    /**
//     * 列表
//     */
//
//
//    /**
//     * 信息
//     */
//    @GetMapping("/info/{id}")
//    public R info(@PathVariable("id") Long id){
//		SubmitBillNameEntity submitBillName = submitBillNameService.getById(id);
//
//        return R.ok().put("submitBillName", submitBillName);
//    }
//
//    /**
//     * 保存
//     */
//    @PostMapping("/save")
//    public R save(@RequestBody SubmitBillNameEntity submitBillName){
//		submitBillNameService.save(submitBillName);
//
//        return R.ok();
//    }
//
//    /**
//     * 修改
//     */
//    @PostMapping("/update")
//    public R update(@RequestBody SubmitBillNameEntity submitBillName){
//		submitBillNameService.updateById(submitBillName);
//
//        return R.ok();
//    }
//
//    /**
//     * 删除
//     */
//    @PostMapping("/delete")
//    public R delete(@RequestBody Long[] ids){
//		submitBillNameService.removeByIds(Arrays.asList(ids));
//
//        return R.ok();
//    }

}
